<?php
/**
 * MongoDig
 *
 * @copyright  Copyright (c) 2010 lanyanguang (http://www.lanyg.com)
 * @license    GNU General Public License 2.0
 * @version    $Id: index.php 3 2010-11-04 07:29:28Z lanyg.com $
 */

/** 初始化 */
require_once 'init.php';

header('Content-type: text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">';
echo "<channel>\r\n";
echo "<title>".$config['site_title']."</title>\r\n";
echo "<language>en-us</language>\r\n";
echo '<atom:link href="'.$config['site_url'].'/xmlfeeds.php" rel="self" type="application/rss+xml" />';
echo "<link>".$config['site_url']."</link>\r\n";
echo "<description>".$config['site_title']."</description>\r\n";
include_logic('topic');
if(isset($_GET['id']))
{
	$cursor = topic_find(array('cat_id'=>$_GET['id']));
}
else
{
	$cursor = topic_find();
}
	$topics = $cursor->sort(array('score' =>-1))->skip(0)->limit(10);
		while ($topics->hasNext())
		{
			$topic = $topics->getNext();
			
			$topic['title'] = str_replace("&","&amp;",$topic['title']);
			$topic['title'] = str_replace('<','&lt;',$topic['title']);
			$topic['title'] = str_replace('>','&gt;',$topic['title']);
			$topic['description'] = str_replace("&","&amp;",$topic['description']);
			$topic['description'] = str_replace('<','&lt;',$topic['description']);
			$topic['description'] = str_replace('>','&gt;',$topic['description']);
			$topic['description'] = str_replace('&lt;br /&gt;','<br />',$topic['description']);
			$topic['description'] = str_replace('&lt;br&gt;','<br>',$topic['description']);

			$topic_link = $config['site_url'].'/topic.php?id='.$topic['_id'];

		
			echo "<item>\r\n";
			echo "<title>".$topic['title']."</title>\r\n";
			echo "<link>".$topic_link."</link>\r\n";
			echo '<guid>' . $topic_link . '</guid>';
			echo "<description><![CDATA[".$topic['description']."]]></description>\r\n";
			echo "<pubDate>".date("r",$topic['entry_time'])."</pubDate>\r\n";
			echo "</item>\r\n";
		}
		
		echo "</channel>\r\n";
		echo "</rss>\r\n";
?>